package tw.raybird.walker.officereader;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

import org.apache.log4j.Logger;



public class CSVReader implements Reader {

	private Logger logger;
	
	public CSVReader(){
		logger = Logger.getRootLogger();
	}
	
	@Override
	public String read(File file) {
//		StringBuilder contents = new StringBuilder();
//		String osEncoding = "utf-8";
//		BigFile bigFile = null;
//		try {
//			bigFile = new BigFile(file, osEncoding);
//			for (String string : bigFile) {
//				contents.append(string);
//				contents.append("\n");
//			}
//		} catch (Exception e) {
//			logger.warn("", e);
//		} finally {
//			Util.close(bigFile);
//		}
//		return contents.toString();
		
		
		StringBuilder contents = new StringBuilder();
		String osEncoding = "utf-8";
		BufferedReader input = null ;
		try {
			input = new BufferedReader(new InputStreamReader(new FileInputStream(file), osEncoding));
			String line = null; // not declared within while loop
			while ((line = input.readLine()) != null) {
				contents.append(line);
				line = null;
			}
		} catch (Exception e) {
			logger.warn("", e);
		} finally{
			Util.close(input);
		}
		String string = contents.toString();
		contents = null;
		input = null;
		return string;
	}
}
